﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace VisualPoint.Controls.Actions
{
    public class SlideActions
    {
        public SlideActions()
        {
            Actions = new ActionCollection();
        }

        [XmlArrayItem(typeof(FileOpenAction))]
        [XmlArrayItem(typeof(FileCloseAction))]
        [XmlArrayItem(typeof(TextWriteAction))]
        [XmlArrayItem(typeof(TextSelectAction))]
        [XmlArrayItem(typeof(ResizeAction))]
        public ActionCollection Actions
        {
            get;
            set;
        }

        public static SlideActions DeSerialize(string data)
        {
            try
            {
                using (StringReader sw = new StringReader(data))
                {
                    XmlSerializer xs = new XmlSerializer(typeof(SlideActions));

                    return xs.Deserialize(sw) as SlideActions;
                }
            }
            catch (Exception ex)
            { }
            return null;
        }

        public string Serialize()
        {
            StringBuilder sb = new StringBuilder();
            using (StringWriter sw = new StringWriter(sb))
            {
                XmlSerializer xs = new XmlSerializer(typeof(SlideActions));

                xs.Serialize(sw, this);
            }
            return sb.ToString();
        }
    }
}
